<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>添加学员</title>
    <script src="/js/jquery.js"></script>
    <script src="/js/myAjax.js"></script>
    <script src="/layui/layui.js"></script>
    <link rel="stylesheet" href="/layui/css/layui.css">
    <script src="/js/user/addStudent.js"></script>
</head>
<body>
<div class="layui-form" style="width: 400px;margin-top: 40px;margin-left: 70px">
    <div type="hidden" id="user-name"></div>
    <div class="layui-form-item">
        <label class="layui-form-label">用户名</label>
        <div class="layui-input-block">
            <input type="text" name="username" id="username" required autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">密码</label>
        <div class="layui-input-inline" style="">
            <input type="password" name="password" id="password" required lay-verify="required" placeholder="请输入密码"
                   autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">姓名</label>
        <div class="layui-input-block">
            <input type="text" name="nickName" id="nickName" required lay-verify="required" placeholder="请输入您的姓名(待补充)"
                   autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">性别</label>
        <div class="layui-input-block">
            <input type="radio" name="sex" value="男" title="男">
            <input type="radio" name="sex" value="女" title="女">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">学历等级</label>
        <div class="layui-input-block">
            <input type="text" name="address" id="education" required lay-verify="required" placeholder="请输入学历(待补充)"
                   autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">激活</label>
        <div class="layui-input-block">
            <input type="checkbox" value="1" name="switch" lay-skin="switch">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">添加时间</label>
        <div class="layui-input-block">
            <input type="text" name="createTime" id="createTime" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="formDemo">确认修改</button>
            <button type="reset" onclick="reseta()" class="layui-btn layui-btn-primary" style="width: 100px">重置</button>
        </div>
    </div>
</div>
<script>
    layui.use('laydate', function () {
        var laydate = layui.laydate;
        //执行一个laydate实例
        laydate.render({
            elem: '#createTime' //指定元素
            , type: 'datetime'
            , format: 'yyyy-MM-dd HH:mm:ss'
        });
    });
    layui.use('form', function () {
        var form = layui.form;

        //监听提交
        form.on('submit(formDemo)', function () {
            // layer.msg(JSON.stringify(data.field));
            let data = {
                username: $("#username").val(),
                password: $("#password").val(),
                nickName: $("#nickName").val(),
                sex: $('input[name="sex"]:checked').val(),
                education: $("#education").val(),
                graduate: $("#graduate").val(),
                createTime: $("#createTime").val(),
                state: $('input:checkbox[name="switch"]:checked').val(),
                type: 3,
            }
            if (data.state == null) {
                data.state = 0;
            }
            console.log(data);
            let result = myAjax('/u/user/add', 'post', data);
            if (result.code === 200) {
                layer.msg("修改成功");
                parent.layer.closeAll();
                parent.location.reload();
            } else if (result.code===401){
                layer.msg("系统繁忙！请稍后再试！");
            }
            return false;
        });
    });

    function reseta() {
        location.assign("/html/user/addTeacher.html")
    }
</script>
</body>
</html>